package com.hexb.smh.config;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author : hexb
 */
@Configuration
public class KaptchaConfig {


    //配置:https://www.cnblogs.com/zhangyuanbo/p/11214078.html
    //透明背景
    @Bean
    public TranslucentProducer getTranslucentProducer() {
        TranslucentProducer dk = new TranslucentProducer();
        dk.setConfig(config());
        return dk;
    }

    public Config config() {
        Properties properties = new Properties();
        // 图片边框
        properties.setProperty(Constants.KAPTCHA_BORDER, "no");
        // 边框颜色
        properties.setProperty(Constants.KAPTCHA_BORDER_COLOR, "0,43,75");
        // 字体颜色
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR, "233,30,99");
        // 图片宽
        properties.setProperty("kaptcha.image.width", "110");
        // 图片高
        properties.setProperty("kaptcha.image.height", "40");
        // 字体大小
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE, "30");
        // session key
        properties.setProperty("kaptcha.session.key", "code");
        // 验证码长度
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        // 字体
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial");
        properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "4");
        properties.setProperty(Constants.KAPTCHA_BACKGROUND_CLR_FROM, "0,43,75");
        properties.setProperty(Constants.KAPTCHA_BACKGROUND_CLR_TO, "0,43,75");
        properties.setProperty(Constants.KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
        properties.setProperty(Constants.KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise");
        properties.setProperty(Constants.KAPTCHA_PRODUCER_IMPL, "com.hexb.smh.config.TranslucentProducer");
        properties.setProperty(Constants.KAPTCHA_BACKGROUND_IMPL, "com.hexb.smh.config.TranslucentBackground");
        Config config = new Config(properties);
        return config;
    }


}
